{{- if gt (len .Values.flowSchema.internal.namespaces) 0 }}
---
  {{- if semverCompare "> 1.29" .Values.global.discovery.kubernetesVersion }}
apiVersion: flowcontrol.apiserver.k8s.io/v1
  {{- else if semverCompare "> 1.26" .Values.global.discovery.kubernetesVersion }}
apiVersion: flowcontrol.apiserver.k8s.io/v1beta3
  {{- else if semverCompare ">= 1.25" .Values.global.discovery.kubernetesVersion }}
apiVersion: flowcontrol.apiserver.k8s.io/v1beta2
  {{- else }}
apiVersion: flowcontrol.apiserver.k8s.io/v1beta1
  {{- end }}
kind: FlowSchema
metadata:
  name: d8-serviceaccounts
  {{- include "helm_lib_module_labels" (list . (dict "app" .Chart.Name)) | nindent 2 }}
spec:
  distinguisherMethod:
    type: ByUser
  matchingPrecedence: 1000
  priorityLevelConfiguration:
    name: d8-serviceaccounts
  rules:
  - resourceRules:
    - apiGroups: ["", "apps/v1", "deckhouse.io", "cilium.io"]
      clusterScope: true
      namespaces: ["*"]
      resources: ["*"]
      verbs: ["list"]
    subjects:
  {{- range $ns := .Values.flowSchema.internal.namespaces }}
    - kind: ServiceAccount
      serviceAccount:
        name: "*"
        namespace: {{ $ns | quote }}
  {{- end }}
{{- end }}
